/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.asseco.bazi2.controllers;

import com.asseco.bazi2.models.Klient;
import com.asseco.bazi2.models.TipSifrarnik;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import com.asseco.mio.core.webapp.controller.BaseFormController;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.asseco.mio.codex.controllers.*;
import org.springframework.validation.Validator;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import oracle.jdbc.OracleTypes;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
import org.springframework.stereotype.Controller;
import org.apache.commons.lang.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 *
 * @author Bojan
 */
@Controller
@RequestMapping("/novtipsifrarnik*")
public class NovTipSifrarnik extends BaseFormController {


    @ModelAttribute(value="tipSif")
    public TipSifrarnik getTipSifrarnik() {

        return new TipSifrarnik();

    }


    @RequestMapping(method = {RequestMethod.GET, RequestMethod.POST})
    protected TipSifrarnik showForm(HttpServletRequest request, HttpServletResponse response)
            throws Exception {


            return new TipSifrarnik();


    }

    @RequestMapping(method = RequestMethod.POST)
    public String onSubmit(TipSifrarnik tipSif, BindingResult errors, HttpServletRequest request,
            HttpServletResponse response) throws SQLException {




           // TipSifrarnik tipSif = new TipSifrarnik();


            Configuration c = new Configuration().configure();
            SessionFactory sf = c.buildSessionFactory();
            Session session = sf.openSession();
            session.beginTransaction();

            Connection con = session.connection();  // obtain JDBC connection from Session object


            CallableStatement cs = con.prepareCall("{ call baza.SIFRARNIK_PACK.dodavanje_type_sif(?) }");

            cs.setString(1, tipSif.getIme());


            cs.execute();


            session.getTransaction().commit();
            session.close();
            sf.close();

        return "redirect:mainMenu";

    }
}
